package fsclient;
import FsInterfaces.IDownloadServer;
import FsInterfaces.ServerBandwidthBean;
import java.rmi.registry.*;

public class Client {

    Registry registry;

    public static void main(String[] args) throws Exception{
        System.out.println(args[0]);
        Client client = new Client(args[0]);
    }

      public Client(String aTitle){


      //the download server doesnot change, therefore we have hardcoded the values
      int port = 2221;
        String host = "localhost";
        String name = "DownloadServer";

        System.out.print("Contacting '"+name+"' @ "+host+":"+port+" to search for the title '"+aTitle+"'");
        try {
            
            registry=LocateRegistry.getRegistry("localhost", port);
            IDownloadServer ds = (IDownloadServer)(registry.lookup(name));
            ServerBandwidthBean serverBandwidthBean = ds.RequestServer(aTitle);

            if(serverBandwidthBean.getServerAddress()!=null){
                System.out.println("Got a response! Best Server Available @ "+serverBandwidthBean.getServerAddress()+" with "+serverBandwidthBean.getServerBandwidth()+" Kb/s");
            }
            else
                System.out.println("No server with file available.");
        }
        catch (Exception e) {
            e.printStackTrace();
        }
    }
}
